package studychinese.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hschinese.pronunciation.R;
import com.hschinese.pronunciation.interfaces.OnItermClickLisenner;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by buba on 2018/2/5.
 */

public class StrokesAdapter extends RecyclerView.Adapter<StrokesAdapter.MyViewHolder> {


    private  int type;
    private  OnItermClickLisenner onItermClickLisenner;
    private LayoutInflater layoutInflater;
    private int[] strs;

    public StrokesAdapter(Context context, int[] strs, int type, OnItermClickLisenner onItermClickLisenner) {
        this.strs = strs;
        this.type = type;
        this.onItermClickLisenner = onItermClickLisenner;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = layoutInflater.inflate(R.layout.item_stroke, parent, false);
        return new MyViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.iv_stroke.setImageResource(strs[position]);
        holder.iv_stroke.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onItermClickLisenner.onClick(position,type);
            }
        });
    }

    @Override
    public int getItemCount() {
        return strs.length;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.iv_stroke)
        ImageView iv_stroke;
        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
